﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using SharpPTCLib;
using Microsoft.DirectX.DirectInput;

namespace SharpPTCSamples
{
    class Starfield
    {

        static void Main(string[] args)
        {
            int s_x;
            int s_y;
            int col;
            int speed = 2;
            int max_stars = 500;
            float an = 0;
            List<star> stars = new List<star>();
            string demoString = "http://www.codeplex.com/SharpPTC";

            Random random = new Random();
            SharpPTC ptc = new SharpPTC();
            ptc.SetClsColor(Color.Black);

            if (!ptc.StartAll("Starfield", 320, 200, 2, false)) return;

            for (int i = 0; i < max_stars; i++)
            {
                star new_star = new star();
                new_star.x = random.Next(-(ptc.Width / 2), (ptc.Width / 2)) << 8;
                new_star.y = random.Next(-(ptc.Height / 2), (ptc.Height / 2)) << 8;
                new_star.z = random.Next(0, 255);
                stars.Add(new_star);
            }

            do
            {
                ptc.Cls();
                foreach (star s in stars)
                {
                    s.z = s.z - speed;
                    if (s.z <= speed)
                        s.z = 255;
                    s_x = (s.x / s.z) + (ptc.Width / 2);
                    s_y = (s.y / s.z) + (ptc.Height / 2);
                    col = 255 - s.z;
                    ptc.SetDrawColor(col, col, col);
                    ptc.DrawPixel(s_x, s_y);
                }

                an += 0.1f;
                an = an % (float)(Math.PI * 2);
                ptc.SetDrawColor(Color.Red);
                for (int i = 0; i < demoString.Length; i++)
                {
                    ptc.DrawLetter((i * 8) + 35, (int)(Math.Sin(an + (i * 0.2)) * 10) + 100, demoString[i]);
                }

                if (ptc.IsKeyDown(Scancode.ESCAPE))
                    break;
            } while (ptc.UpdateAll());
            ptc.CloseAll();
        }
    }

    class star
    {
        public int x, y, z;
    }
}
